import { defineStore } from 'pinia'

import { allAsyncRoutes, anyRoute, staticRoutes } from '@/router/routes'
import type { RouteRecordName, RouteRecordRaw } from 'vue-router'
import router from '@/router'
import categoryApi from '@/api/category'
import type { categoryL1ListType } from '@/api/category'
// pinia的state是一个函数，函数的形参和返回值类型要确定

// interface UserInfoStoreStateData {
//   token: string | null;
//   userInfo: UserInfoData;
//   menuRoutes: RouteRecordRaw[];
// }

export const useCategoryInfoStore = defineStore('categoryInfo', {
  state(): categoryL1ListType {
    return {
      categoryGroupList: [],
      categoryL1List: [],
      categoryL2List: [],
      currentCategory: {
        bannerList: [],
        categoryType: '',
        id: '',
        name: '',
        subCateList: [],
        superCategoryId: '',
        type: ''
      }
      // token: getToken() as string,//自动登录
    }
  },

  actions: {
    async getCategoryInfo(id: number) {
      let res = await categoryApi.getGoodsInfo(id)
      console.log(res)

      this.categoryGroupList = res.categoryGroupList || []
      this.categoryL1List = res.categoryL1List || []
      this.categoryL2List = res.categoryL2List || []
      this.currentCategory = res.currentCategory || {}
      //   console.log(res)
    },
    async getGoodsList(id: number) {
      let res = await categoryApi.getGoodsList(id)
      this.categoryL2List = res.categoryL2List || []
      console.log(res)
    }
  }
})
